import {Component, Input} from '@angular/core';
import {CommonPage} from '../../../../../page/system/common-page';
import {SwitchColor} from '../../enums';

@Component({
  templateUrl: './field.component.html'
})
export class FieldComponent extends CommonPage {

  @Input() set fields(v) {
    this.checkedFields = v;
    if (this.checkedFields.length == this.options.length) {
      this.isCheckAll = true;
    } else {
      this.isCheckAll = false;
    }
  };

  @Input() options = [];

  checkedFields = [];
  type = SwitchColor.RED;
  isCheckAll = true;

  checkAll(v) {
    if (v) {
      this.fields = this.options.map(({value}) => value);
    } else {
      this.fields = this.options.filter(item => item.disabled).map(({value}) => value);
    }
  }

  onValueChange(value) {
    if (value.length == this.options.length) {
      this.isCheckAll = true;
    } else {
      this.isCheckAll = false;
    }
  }


}







